<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('get_utf8_word'))
{
	function get_utf8_word($string, $length = 80,$more=1 , $etc = '..')
	{
	$strcut = '';
	$strLength = 0;
	$width  = 0;
	if(strlen($string) > $length) {
		//将$length换算成实际UTF8格式编码下字符串的长度
		for($i = 0; $i < $length; $i++) {
			if ( $strLength >= strlen($string) ){
				break;
			}
			if ( $width>=$length){
				break;
			}
			//当检测到一个中文字符时
			if( ord($string[$strLength]) > 127 ){
				$strLength += 3;
				$width     += 2;              //大概按一个汉字宽度相当于两个英文字符的宽度
			}else{
				$strLength += 1;
				$width     += 1;
			}
		}
		return substr($string, 0, $strLength).$etc;
	} else {
		return $string;
	}
	}
}

if ( ! function_exists('clean')) {  
    function clean($string) {  
    $string=strtolower($string);
        $keywords= array(  
            'select' => 's*t',  
            'from' => 'f*m',  
            'union' => 'un**n',  
            'limit' => 'l*mt',
             'update' => 'up**e',  
            'insert' => 'in*t',   
         'file' => 'fi*e',  
        'session' => 'se*n', 
        'cookie' => 'c*ie', 
        'script' => 's*pt',  
        'ascii' => 'as*ii',  
         'into' => 'i*to', 
         'fopen' => 'f*en',
        'fwrite' => 'f*te',   
            'where' => 'ww*r*e'          
            );  
        return strtr($string, $keywords);  
    }  
} 


if ( ! function_exists('filtrate'))
{
	function filtrate($msg)
	{
	//$msg = str_replace('&','&amp;',$msg);
	//$msg = str_replace(' ','&nbsp;',$msg);
	$msg = str_replace('"','&quot;',$msg);
	$msg = str_replace("'",'&#39;',$msg);
	$msg = str_replace("<","&lt;",$msg);
	$msg = str_replace(">","&gt;",$msg);
	$msg = str_replace("\t","   &nbsp;  &nbsp;",$msg);
	//$msg = str_replace("\r","",$msg);
	$msg = str_replace("   "," &nbsp; ",$msg);
	return $msg;
	}
}

